package gui.swing;

import javax.swing.*;
import java.awt.*;

public class TestJButton extends JFrame {

    public TestJButton(){
        Container contentPane = this.getContentPane();
        //将一个图片变为图标
        String url = "E:\\new PC\\study\\java学习\\code\\JavaSE\\基础语法\\src\\gui\\swing\\zsh.jpg";

        Icon icon = new ImageIcon(url);

        //把图标放在按钮上
        JButton jButton = new JButton();
        jButton.setIcon(icon);
        jButton.setToolTipText("图片按钮");

        contentPane.add(jButton);

        this.setVisible(true);
        this.setBounds(100,100,200,200);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) {
        new TestJButton();
    }
}
